﻿package bdz.projects.lavender.doi.utils {
	import flash.display.MovieClip;
	import flash.events.EventDispatcher;
	import flash.filters.*;
	
	import gs.*;
	import gs.easing.*;
	/**
	 * ...
	 * @author ...
	 */
	public class DOITweens extends EventDispatcher {
		public static var TWEENSPEED:Number = 1;
		public static var DEFAULTEASE:Function = Strong.easeInOut;
		
		public static function scaleUp(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleX:1, scaleY:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleTo(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleX:amount, scaleY:amount, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleToX(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleX:amount, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleToY(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleY:amount, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleFrom(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			targ.scaleX = targ.scaleY = amount;
			TweenMax.to(targ, time, { scaleX:1, scaleY:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleFromX(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			targ.scaleX = amount;
			TweenMax.to(targ, time, { scaleX:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleFromY(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			targ.scaleY = amount
			TweenMax.to(targ, time, { scaleY:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		
		public static function scaleDown(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleX:0, scaleY:0, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function scaleUpY(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleY:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleDownY(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleY:0, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function scaleUpX(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleX:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function scaleDownX(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { scaleX:0, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function moveOutRight(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			var dx:Number;
			
			if (targ.root == targ.parent) {
				dx = Math.ceil(targ.stage.stageWidth)+targ.width*2;
			}else {
				dx = Math.ceil(targ.parent.width)+targ.width*2;
			}
			TweenMax.to(targ, time, { x:dx, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function moveOutLeft(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			var dx:Number;
			if (targ.root == targ.parent) {
				dx = -targ.width*2;
			}else {
				dx = -targ.width*2;
			}
			TweenMax.to(targ, time, { x:dx, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function moveOutTop(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			var dy:Number;
			if (targ.root == targ.parent) {
				dy = -(targ.height*2);
			}else {
				dy = -(targ.height*2);
			}
			
			TweenMax.to(targ, time, { y:dy, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function moveOutBottom(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			var dy:Number;
			if (targ.root == targ.parent) {
				dy = Math.ceil(targ.stage.stageHeight)+targ.height*2;
			}else {
				dy = Math.ceil(targ.parent.height)+targ.height*2;
			}
			TweenMax.to(targ, time, { y:dy, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function moveToCenter(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			var dx:Number;
			var dy:Number;
			if (targ.root == targ.parent) {
				dx = Math.ceil(targ.stage.stageWidth / 2);
				dy = Math.ceil(targ.stage.stageHeight / 2);
			}else {
				dx = Math.ceil(targ.parent.width / 2);
				dy = Math.ceil(targ.parent.height / 2);
			}
			TweenMax.to(targ, time, { x:dx, y:dy, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function changeColor(targ:MovieClip, time:Number, clr:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { tint:clr, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete} );
		}
		public static function removeColor(targ:MovieClip, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { removeTint:true, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function moveToX(targ:MovieClip, time:Number, coords:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { x:coords, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function moveToY(targ:MovieClip, time:Number, coords:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { y:coords, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function moveToCoordinate(targ:MovieClip, time:Number, coords:Object, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, { x:coords.x, y:coords.y, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function blurTo(targ:MovieClip, time:Number, amount:Number,  delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, {blurFilter:{blurX:amount, blurY:amount}, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function glowTo(targ:MovieClip, time:Number, amount:Number, clr:Number, str:Number = 3, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, {glowFilter:{alpha:1, strength:str, color:clr, blurX:amount, blurY:amount}, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function blurFrom(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			targ.filters = [new BlurFilter(amount, amount)];
			TweenMax.to(targ, time, {blurFilter:{blurX:0, blurY:0}, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function blurToX(targ:MovieClip, time:Number, amount:Number,  delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, {blurFilter:{blurX:amount}, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function blurFromX(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			targ.filters = [new BlurFilter(amount, 0)];
			TweenMax.to(targ, time, {blurFilter:{blurX:0}, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function blurToY(targ:MovieClip, time:Number, amount:Number,  delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, {blurFilter:{blurY:amount}, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function blurFromY(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			targ.filters = [new BlurFilter(0, amount)];
			TweenMax.to(targ, time, {blurFilter:{blurY:0}, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function rotateTo(targ:MovieClip, time:Number, amount:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to(targ, time, {rotation:amount, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function fadeIn(targ:*, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.from(targ, time, {alpha:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
		}
		public static function fadeOut(targ:*, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			TweenMax.to (targ, time, { alpha:0, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
			
		}
		public static function fadeInGroup(targ:Array, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			
			for (var i:int = 0; i < targ.length; i++) {
				var obj:Object = targ[i];
				TweenMax.from(obj, time, {alpha:1, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
			}
		}
		public static function fadeOutGroup(targ:Array, time:Number, delay:Number = 0, ease:Function = null, complete:Function = null) {
			
			for (var i:int = 0; i < targ.length; i++) {
				var obj:Object = targ[i];
				TweenMax.to (obj, time, { alpha:0, ease:ease || DEFAULTEASE, delay:delay, onComplete:complete } );
			}
		}
		
		public static function colorTrans ( target:MovieClip, time:Number, color:Number = 0x000, amount:Number = 0.5, delay:Number = 0, onComplete:Function = null ) {
			TweenMax.to(target, time, {colorMatrixFilter:{colorize:color, amount:amount}, delay:delay});
		}
	}
	
}